export function isWeChatBrowserPro() {
  const ua = navigator.userAgent.toLowerCase();
  return (
    ua.indexOf("micromessenger") !== -1 ||
    typeof window.WeixinJSBridge !== "undefined"
  );
}
export function parseUserAgent() {
  const ua = navigator.userAgent;

  return {
    os: {
      type: ua.match(/Android|iPhone|iPad|iPod|Windows/i)?.[0],
      version: ua
        .match(/(?:Android\s([\d.]+))|(?:OS\s([\d_]+))/i)
        ?.slice(1)
        .find(v => v)
    },
    device: {
      brand: ua.match(/(Huawei|Xiaomi|vivo)/i)?.[1],
      model: ua.match(/(?:Build\/.*;\s)([A-Za-z0-9\s]+)\sBuild/i)?.[1]
    },
    browser: {
      engine: ua.match(/(AppleWebKit|Gecko)\/([\d.]+)/i)?.slice(1),
      version: ua.match(/(Chrome|Firefox)\/([\d.]+)/i)?.[2]
    },
    wechat: ua.match(/MicroMessenger\/([\d.]+)/i)?.[1],
    network: ua.match(/NetType\/(WIFI|4G|5G)/i)?.[1]
  };
}
